C code for getting and setting group sort fields

The Crystal Report Engine includes two functions for getting information from a report about group sort fields:

as well as a third function for changing information in an existing group sort field or adding a new group sort field to the report, PESetNthGroupSortField. The following sample code demonstrates techniques for using each of these three functions:

short         nGroupSortFields;                // Will receive number of sort fields
short     groupSortFieldN;        // Indicates specific group sort field
HANDLE nameHandle;            // Pointer to name of group sort field
short     nameLength;            // Length of group sort field name
short     direction;            // Sort direction
char *groupSortFieldName         // Holds actual group sort field name
short     newDirection            // New group sort field direction
char newGroupSortName [] = "Count({customer.CUSTOMER},
{customer.CITY})";            // New group sort field name nGroupSortFields = PEGetNGroupSortFields(Job);
if (nGroupSortFields < 0){
    // Handle error
} groupSortFieldN = 0;
// The first group sort field in the report if (!PEGetNthGroupSortField(Job, groupSortFieldN, &nameHandle,
&nameLength, &direction)){
    // Handle error
}     // nameLength now contains the length of the string in nameHandle
    // direction now contains either
    // PE_SF_ASCENDING or PE_SF_DESCENDING     // allocate groupSortFieldName buffer
groupSortFieldName = (char*)malloc(nameLength);     // Retrieve the group sort field name
if (!PEGetHandleString(nameHandle, groupSortFieldName,nameLength)){
    // Handle error
}     // groupSortFieldName now contains the group sort field
    // Now we will add a new group sort field
newDirection = PE_SF_ASCENDING     // By using the value returned by PEGetNGroupSortFields in     // PESetNthGroupSortField, we add a new group
    // sort field to the report: if (!PESetNthGroupSortField(Job, nGroupSortFields,
newGroupSortName, newDirection)){
    // Handle error
}


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com